from selenium.webdriver.common.by import By
from time import sleep
from selenium import webdriver


driver = webdriver.Chrome()
driver.get('https://mail.163.com/')

# 最大化窗口
driver.maximize_window()

cookies = [
    {
        'name': 'NTES_SESS',
        'value': 'qJE8Q9Vj5oy1lIQr12s2rQp3Hph0GBDZFGgpel1KM8fHtMe.tG1VzrJfMb7R79RupifucjUv8xb4nalsxYutPhkVxBu1_m1LFils4PpDlvZnpXoQdzehntiF7Wy59yXdcIQjw57rELfyBjRBtbxBTcFVryXQp7X5EUX3Pd6YHc43GWnwETeHxmpfrL11YsJAl2EwW69JOmTz0jKzvMkYC4CLo'
    },
    {
        'name': 'Coremail',
        'value': 'b4428fb65cb29%xAnilhjYkbrBSDaENIYYHkzOIpMMcRza%g5a46.mail.163.com'
    },
    {
        'name': 'MAIL_ENTRY_INFO',
        'value': '1|0|mail163|mail163_letter|221.234.130.94|2fa6d1008c4c1e32b85cc4b321f388ed_v1|'
    },
    {
        'name': 'MAIL_ENTRY_CS',
        'value': '64f722054605c5ff15efaddee608ca5b'
    },
    {
        'name': 'cm_last_info',
        'value': 'dT1xcWNvbTE2OTU5ODI0NTYlNDAxNjMuY29tJmQ9aHR0cHMlM0ElMkYlMkZtYWlsLjE2My5jb20lMkZqczYlMkZtYWluLmpzcCUzRnNpZCUzRHhBbmlsaGpZa2JyQlNEYUVOSVlZSGt6T0lwTU1jUnphJnM9eEFuaWxoallrYnJCU0RhRU5JWVlIa3pPSXBNTWNSemEmaD1odHRwcyUzQSUyRiUyRm1haWwuMTYzLmNvbSUyRmpzNiUyRm1haW4uanNwJTNGc2lkJTNEeEFuaWxoallrYnJCU0RhRU5JWVlIa3pPSXBNTWNSemEmdz1odHRwcyUzQSUyRiUyRm1haWwuMTYzLmNvbSZsPS0xJnQ9LTEmYXM9dHJ1ZQ=='
    },

]
for cookie1 in cookies:
    driver.add_cookie(cookie1)
sleep(2)
driver.refresh()

# 点击写信
driver.find_element(By.ID, "_mail_component_149_149").click()
sleep(2)
# 输入收件人
driver.find_element(By.CLASS_NAME, "nui-editableAddr-ipt").send_keys('张三')

# 获取到主题 输入主题内容
sleep(2)
nt = driver.find_elements(By.CLASS_NAME, 'nui-ipt-input')[2]
nt.send_keys('邮件')

# 定位到iframe
sleep(2)
iframe = driver.find_element(By.CLASS_NAME, "APP-editor-iframe")

# 切换到iframe
driver.switch_to.frame(iframe)

# 获取文本框并文本框输入内容
driver.find_element(By.CLASS_NAME, 'nui-scroll').send_keys('123456')
sleep(2)

# 切换到主页面
driver.switch_to.default_content()

# 点击主页面的发送按钮
nxt = driver.find_elements(By.CLASS_NAME, 'nui-btn-text')[2]
nxt.click()

# 退出浏览器
sleep(4)
driver.quit()



